
import 'package:flutter/material.dart';
import 'package:getx_scaffold/getx_scaffold.dart';
import 'package:oramemo/common/styles/colors.dart';
import 'package:oramemo/pages/transcription/files/controllers/transcriptio_files_logic.dart';

import 'ai_transcription_logic.dart';

class FileSelectSheet extends StatelessWidget {
  FileSelectSheet({
    super.key,
  });

  final TranscriptionFilesLogic fileLogic = Get.find();
  final AiTranscriptionLogic logic = Get.find();

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.fromLTRB(12.0, 10.0, 12.0, 0.0),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(12),
      ),
      child: ListView(
        children: [
          FileSelectItem(
            title: fileLogic.defaultFolder.folderName ?? '',
            onTap: () {
              fileLogic.currentFolder.value = fileLogic.defaultFolder;
              logic.requestData(page: 1);
              Get.back();
            },
          ),
          for (final file in fileLogic.list)
            FileSelectItem(
              title: file.folderName ?? '',
              onTap: () {
                fileLogic.currentFolder.value = file;
                logic.requestData(page: 1);
                Get.back();
              },
            ),
        ],
      ),
    );
  }
}

class FileSelectItem extends StatelessWidget {
  const FileSelectItem({
    super.key,
    required this.title,
    required this.onTap,
  });

  final String title;

  final Function() onTap;

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: onTap,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            padding: const EdgeInsets.fromLTRB(12.0, 15.0, 12.0, 15.0),
            child: Text(
              title,
              style: const TextStyle(
                fontSize: 14,
                color: Colours.text,
              ),
            ),
          ),
          const Divider(height: 1),
        ],
      ),
    );
  }
}
